<template>
  <div>
    <h2>评价管理</h2>
    <Common addTitle="添加评价" type="evaluate" :username="this.username" :empNo="this.empNo" :users="this.users"
      :tableDataProp="this.remarkData" @addEvaluate="addEvaluate"></Common>
  </div>
</template>

<script>

import Common from '../../components/performance/common.vue'
import { getUserList } from '@/api/staffs'
import { getRemark, addRemark, delRemark } from '@/api/remark'


export default {
  name: 'evaluate',
  components: {
    Common
  },
  data() {
    return {
      username: "",
      empNo: 0,
      users: [],
      remarkData: [{
        date: '2016-05-04',
        name: '王小虎11',
        address: '上海市普陀区金沙江路 1517 弄',
        visible: false
      }]
    }
  },
  mounted() {
    this.username = localStorage.getItem("uname");
    this.empNo = localStorage.getItem("empNo") * 1;

    this.getUserListFn();
    this.getRemarkFn();
  },
  methods: {
    async getUserListFn() {
      let { data: { rows } } = await getUserList();
      console.log("用户是：", rows);
      let filterRows = rows.filter(item => item.emp_no != this.empNo);
      this.users = filterRows;
    },
    // 添加
    async addEvaluate(payload) {
      console.log("123:", payload)
      let { remark: evaluationContent, remarkType: evaluationType, evaluated_emp_no: evaluatedUser, evaluated_emp_no: evaluatedEmpNo } = payload;
      // let remarkaddData = {evaluationContent}
      let { data } = await addRemark({ content: evaluationContent, type: evaluationType, empName: evaluatedUser, empNo: this.empNo, empName: this.username, evaluatedEmpNo });
      console.log(data)
      if (data.code === 200) {
        this.getRemarkFn();
      }
    },
    // 获取评价数据
    async getRemarkFn() {
      let { data: { rows } } = await getRemark();
      this.remarkData = rows;
    }
  }
}
</script>

<style></style>